package com.sagframe.sagacity.sqltoy.plus.dao;

import com.sagframe.sagacity.sqltoy.plus.MultiFiledMappingStrategy;
import org.sagacity.sqltoy.config.model.EntityMeta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SqlToyMultiFiledMappingStrategy implements MultiFiledMappingStrategy {

    @Autowired
    private SqlToyEntityMetaCache entityMetaCache;

    @Override
    public String getEntityName(Class<?> clazz) {
        return getEntityMeta(clazz).getTableName();
    }

    @Override
    public String getColumnName(Class<?> clazz, String filedName) {
        return getEntityMeta(clazz).getColumnName(filedName);
    }

    @Override
    public String[] getEntityFields(Class<?> clazz) {
        return getEntityMeta(clazz).getFieldsArray();
    }

    private EntityMeta getEntityMeta(Class<?> clazz) {
        return entityMetaCache.getEntityMeta(clazz);
    }
}
